/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jsysacc.asistencia.view.gui.maestros;

import com.cerd.util.BaseSP01.JUtilBaseSP01;
import com.jsysacc.asistencia.model.beans.maestros.Area;
import com.jsysacc.asistencia.model.beans.maestros.Cargo;
import com.jsysacc.asistencia.model.beans.maestros.Horario;
import com.jsysacc.asistencia.model.beans.maestros.Personal;
import com.jsysacc.asistencia.model.beans.maestros.TipoDocumento;
import com.jsysacc.asistencia.model.beans.maestros.Ubigeo;
import com.jsysacc.asistencia.model.beans.maestros.Via;
import com.jsysacc.asistencia.model.beans.maestros.Zona;
import com.jsysacc.asistencia.model.logic.maestros.PersonalLogic;
import com.jsysacc.asistencia.view.resources.commons.JLogicInterfaz;
import com.jsysacc.asistencia.view.resources.commons.JTextFieldToUpperCase;
import java.util.ArrayList;
import java.util.Date;
import java.util.ResourceBundle;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import org.joda.time.DateTime;

/**
 *
 * @author Carlos
 */
public class FormDialogMantPersonal extends javax.swing.JDialog implements JLogicInterfaz {

    PersonalLogic logic = new PersonalLogic();
    private boolean esNuevo;
    private String codPersonal;
    private String cod_dep, cod_prov, cod_dist;

    //variable locales
    private Personal entityPersonal;

    private final ResourceBundle rbMensajes = ResourceBundle.getBundle("com.jsysacc.asistencia.view.resources.commons.Mensajes");
    private final JUtilBaseSP01 JUB = JUtilBaseSP01.JUtilBaseSP01;

    /**
     * Creates new form FormDialogMantPersonal
     */
    public FormDialogMantPersonal(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    private void llenarComboAreas() {
        this.jcbArea.removeAllItems();
        try {
            ArrayList<Area> listArea = logic.getAreasAll();
            for (Area oArea : listArea) {
                this.jcbArea.addItem(oArea);
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
        }
    }

    private void llenarComboTipoDocumentos() {
        this.jcbTipoDocumento.removeAllItems();
        try {
            ArrayList<TipoDocumento> listTipoDocumento = logic.getTipoDocumentosAll();
            for (TipoDocumento oTipoDocumento : listTipoDocumento) {
                this.jcbTipoDocumento.addItem(oTipoDocumento);
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
        }
    }

    private void llenarComboDepartamentos() {
        this.jcbDepartamento.removeAllItems();
        try {
            ArrayList<Ubigeo> listDepartamentos = logic.getDepartamentosAll(null);
            for (Ubigeo oDepartamento : listDepartamentos) {
                this.jcbDepartamento.addItem(oDepartamento);
            }

            if (!JUB._vacio(cod_dep)) {
                this.jcbDepartamento.setSelectedItem(cod_dep);
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
        }
    }

    private void llenarComboProvincias() {
        this.jcbProvincia.removeAllItems();
        try {
            ArrayList<Ubigeo> listProvincias = logic.getProvinciasByCodDep(cod_dep);
            for (Ubigeo oProvincia : listProvincias) {
                this.jcbProvincia.addItem(oProvincia);
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
        }
    }

    private void llenarComboDistritos() {
        this.jcbDistrito.removeAllItems();
        try {
            ArrayList<Ubigeo> listDistritos = logic.getDistritosByCodProv(cod_dep, cod_prov);
            for (Ubigeo oDistrito : listDistritos) {
                this.jcbDistrito.addItem(oDistrito);
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
        }
    }

    private void llenarComboCargos() {
        this.jcbCargo.removeAllItems();
        try {
            ArrayList<Cargo> listCargo = logic.getCargosAll();
            for (Cargo oCargo : listCargo) {
                this.jcbCargo.addItem(oCargo);
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
        }
    }

    private void llenarComboVias() {
        this.jcbVia.removeAllItems();
        try {
            ArrayList<Via> listVia = logic.getViasAll();
            for (Via oVia : listVia) {
                this.jcbVia.addItem(oVia);
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
        }
    }

    private void llenarComboZonas() {
        this.jcbZona.removeAllItems();
        try {
            ArrayList<Zona> listZona = logic.getZonasAll();
            for (Zona oZona : listZona) {
                this.jcbZona.addItem(oZona);
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
        }
    }

    private void llenarComboHorarios() {
        this.jcbHorario.removeAllItems();
        try {
            ArrayList<Horario> listHorarios = logic.getHorariosAll();
            for (Horario oHorario : listHorarios) {
                this.jcbHorario.addItem(oHorario);
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
        }
    }

    private void limpiar() {
        this.jtxtCodigo.setText("");
        this.jcbTipoDocumento.setSelectedIndex(0);
        this.jtxtNumeroDocumento.setText("");
        this.jtxtApellidoPaterno.setText("");
        this.jtxtApellidoMaterno.setText("");
        this.jtxtPrimerNombre.setText("");
        this.jtxtSegundoNombre.setText("");
        this.jcbSexo.setSelectedIndex(0);
        this.jcbEstadoCivil.setSelectedIndex(0);
        this.jtxtEmail.setText("");
        this.jtxtTelefono.setText("");
        this.jtxtCelular.setText("");
        this.jcbDepartamento.setSelectedIndex(0);
        this.jtxtDireccion.setText("");
        this.jtxtZona.setText("");
        this.jtxtObservacion.setText("");
        this.jcbArea.setSelectedIndex(0);
        this.jcbCargo.setSelectedIndex(0);
        this.jcbHorario.setSelectedIndex(0);
        this.jcbTipoCese.setSelectedIndex(0);

        this.jdtFechaCese.setDate(null);
        this.jtxtMotivoCese.setText("");
        this.jtxtRemuneracion.setText("0.00");
        this.jdtFechaCese.setEnabled(false);
        this.jtxtMotivoCese.setEditable(false);
    }

    //metodo para saber si viene del modificar o del nuevo
    private void llenarData() {

        if (esNuevo) {
            limpiar();
        } else {
            limpiar();
            try {
                Personal oPersonal = logic.getByPk(codPersonal);
                if (JUB._vacio(oPersonal)) {
                    JOptionPane.showMessageDialog(this, " REGISTRO CON CÓDIGO: " + codPersonal + " NO EXISTE EN LA BD.", rbMensajes.getString("MSG_MEN_PRI"), 0);
                } else {
                    setEntity(oPersonal);
                    this.jtxtNumeroDocumento.requestFocus();
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jbtnAceptar = new javax.swing.JButton();
        jbtnCancelar = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtxtCodigo = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jchkEstado = new javax.swing.JCheckBox();
        jLabel4 = new javax.swing.JLabel();
        jcbTipoDocumento = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jtxtNumeroDocumento = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jtxtApellidoPaterno = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jtxtApellidoMaterno = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jtxtPrimerNombre = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jtxtSegundoNombre = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jdtFechaNacimiento = new com.toedter.calendar.JDateChooser();
        jLabel10 = new javax.swing.JLabel();
        jcbSexo = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jcbEstadoCivil = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jtxtEmail = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jtxtTelefono = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jtxtCelular = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        jcbDepartamento = new javax.swing.JComboBox();
        jLabel16 = new javax.swing.JLabel();
        jcbProvincia = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        jcbDistrito = new javax.swing.JComboBox();
        jPanel4 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        jcbVia = new javax.swing.JComboBox();
        jtxtDireccion = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jcbZona = new javax.swing.JComboBox();
        jtxtZona = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtxtObservacion = new javax.swing.JTextArea();
        jPanel5 = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        jcbArea = new javax.swing.JComboBox();
        jLabel22 = new javax.swing.JLabel();
        jdtFechaIngreso = new com.toedter.calendar.JDateChooser();
        jLabel23 = new javax.swing.JLabel();
        jcbCargo = new javax.swing.JComboBox();
        jLabel24 = new javax.swing.JLabel();
        jcbHorario = new javax.swing.JComboBox();
        jLabel25 = new javax.swing.JLabel();
        jcbTipoCese = new javax.swing.JComboBox();
        jLabel26 = new javax.swing.JLabel();
        jdtFechaCese = new com.toedter.calendar.JDateChooser();
        jLabel27 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtxtMotivoCese = new javax.swing.JTextArea();
        jLabel28 = new javax.swing.JLabel();
        jtxtRemuneracion = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jbtnAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jsysacc/asistencia/view/resources/icons/px_24_24/btn_ok_24.png"))); // NOI18N
        jbtnAceptar.setText("Aceptar");
        jbtnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAceptarActionPerformed(evt);
            }
        });

        jbtnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jsysacc/asistencia/view/resources/icons/px_24_24/btn_cancelar_24.png"))); // NOI18N
        jbtnCancelar.setText("Cancelar");
        jbtnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCancelarActionPerformed(evt);
            }
        });

        jTabbedPane1.setFocusable(false);

        jLabel1.setText("Código");

        jtxtCodigo.setEditable(false);
        jtxtCodigo.setBackground(java.awt.SystemColor.inactiveCaption);

        jLabel5.setText("Estado");

        jchkEstado.setText("Activo");

        jLabel4.setText("Tipo de Doc.");

        jLabel2.setText("Número de Doc.");

        jLabel6.setText("Apellido Paterno");

        jLabel7.setText("Apellido Materno");

        jLabel8.setText("Primer Nombre");

        jLabel9.setText("Segundo Nombre");

        jLabel3.setText("Fecha Nac.");

        jLabel10.setText("Sexo");

        jcbSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "M - MASCULINO", "F - FEMENINO" }));

        jLabel11.setText("Estado Civil");

        jcbEstadoCivil.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "C - CASADO", "D - DIVORCIADO", "S - SOLTERO", "V - VIUDO" }));
        jcbEstadoCivil.setSelectedIndex(2);

        jLabel12.setText("E-mail");

        jLabel13.setText("Teléfono");

        jLabel14.setText("Celular");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6)
                    .addComponent(jLabel8)
                    .addComponent(jLabel3)
                    .addComponent(jLabel11)
                    .addComponent(jLabel13)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jchkEstado)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jtxtTelefono, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jcbEstadoCivil, javax.swing.GroupLayout.Alignment.LEADING, 0, 210, Short.MAX_VALUE)
                        .addComponent(jdtFechaNacimiento, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jtxtPrimerNombre, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jcbTipoDocumento, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jtxtApellidoPaterno, javax.swing.GroupLayout.Alignment.LEADING)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel7)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10)
                    .addComponent(jLabel12)
                    .addComponent(jLabel14))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jtxtEmail, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcbSexo, javax.swing.GroupLayout.Alignment.LEADING, 0, 210, Short.MAX_VALUE)
                    .addComponent(jtxtSegundoNombre, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtApellidoMaterno, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtNumeroDocumento, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtCelular))
                .addContainerGap(36, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel1)
                    .addComponent(jtxtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel4)
                    .addComponent(jcbTipoDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jtxtNumeroDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel6)
                    .addComponent(jtxtApellidoPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jtxtApellidoMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel8)
                    .addComponent(jtxtPrimerNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jtxtSegundoNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel3)
                    .addComponent(jdtFechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jcbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel11)
                    .addComponent(jcbEstadoCivil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jtxtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel13)
                    .addComponent(jtxtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel5)
                    .addComponent(jchkEstado))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Datos Generales", new javax.swing.ImageIcon(getClass().getResource("/com/jsysacc/asistencia/view/resources/icons/px_16_16/btn_mant_16.png")), jPanel1); // NOI18N

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Ubigeo"));

        jLabel15.setText("Departamento");

        jcbDepartamento.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbDepartamentoItemStateChanged(evt);
            }
        });

        jLabel16.setText("Provincia");

        jcbProvincia.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbProvinciaItemStateChanged(evt);
            }
        });

        jLabel17.setText("Distrito");

        jcbDistrito.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbDistritoItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel15)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbDepartamento, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jcbProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jcbDistrito, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(13, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel15)
                    .addComponent(jcbDepartamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16)
                    .addComponent(jcbProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17)
                    .addComponent(jcbDistrito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Dirección"));

        jLabel18.setText("Vía");

        jLabel19.setText("Zona");

        jLabel20.setText("Observación");

        jtxtObservacion.setColumns(20);
        jtxtObservacion.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
        jtxtObservacion.setRows(5);
        jScrollPane1.setViewportView(jtxtObservacion);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19)
                            .addComponent(jLabel18))
                        .addGap(46, 46, 46)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jcbVia, 0, 187, Short.MAX_VALUE)
                            .addComponent(jcbZona, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtxtDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE)
                            .addComponent(jtxtZona)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel18)
                    .addComponent(jcbVia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel19)
                    .addComponent(jcbZona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxtZona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel20)
                        .addGap(0, 36, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Datos Domicilio", new javax.swing.ImageIcon(getClass().getResource("/com/jsysacc/asistencia/view/resources/icons/px_16_16/domicilio_16_16.png")), jPanel2); // NOI18N

        jLabel21.setText("Área:");

        jcbArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbAreaActionPerformed(evt);
            }
        });

        jLabel22.setText("Fecha de Ingreso");

        jLabel23.setText("Cargo");

        jLabel24.setText("Horario");

        jLabel25.setText("Tipo de Cese");

        jcbTipoCese.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  -", "VC - VENCIMIENTO DEL CONTRATO", "RV - RENUNCIA VOLUNTARIA", "FA - FALLECIMIENTO" }));
        jcbTipoCese.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbTipoCeseItemStateChanged(evt);
            }
        });

        jLabel26.setText("Fecha de Cese");

        jLabel27.setText("Motivo de Cese");

        jtxtMotivoCese.setColumns(20);
        jtxtMotivoCese.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
        jtxtMotivoCese.setRows(5);
        jScrollPane2.setViewportView(jtxtMotivoCese);

        jLabel28.setText("Remuneración");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel27)
                    .addComponent(jLabel25)
                    .addComponent(jLabel23)
                    .addComponent(jLabel21))
                .addGap(16, 16, 16)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcbTipoCese, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcbArea, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcbCargo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel22)
                    .addComponent(jLabel24)
                    .addComponent(jLabel26)
                    .addComponent(jLabel28))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jcbHorario, 0, 209, Short.MAX_VALUE)
                        .addComponent(jdtFechaCese, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jdtFechaIngreso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jtxtRemuneracion, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel21)
                    .addComponent(jcbArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel22)
                    .addComponent(jdtFechaIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel23)
                    .addComponent(jcbCargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel24)
                    .addComponent(jcbHorario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel25)
                    .addComponent(jcbTipoCese, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel26)
                    .addComponent(jdtFechaCese, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel28)
                        .addComponent(jtxtRemuneracion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel27))
                .addContainerGap(94, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Datos Laborales", new javax.swing.ImageIcon(getClass().getResource("/com/jsysacc/asistencia/view/resources/icons/px_16_16/job_16_16.png")), jPanel5); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbtnAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jbtnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 700, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnAceptar)
                    .addComponent(jbtnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jbtnCancelarActionPerformed

    private void jbtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAceptarActionPerformed
        // TODO add your handling code here:

        if (!hayErroresInput()) {

            getEntity();

            try {
                if (esNuevo) {
                    if (logic.insert(entityPersonal)) {
                        JOptionPane.showMessageDialog(this, rbMensajes.getString("MSG_INS_OK"), rbMensajes.getString("MSG_MEN_PRI"), 1);
                        this.dispose();
                    } else {
                        JOptionPane.showMessageDialog(this, rbMensajes.getString("MSG_INS_ERROR"), rbMensajes.getString("MSG_MEN_PRI"), 0);
                    }
                } else {
                    if (logic.update(entityPersonal)) {
                        JOptionPane.showMessageDialog(this, rbMensajes.getString("MSG_UPD_OK") + " " + codPersonal, rbMensajes.getString("MSG_MEN_PRI"), 1);
                        this.dispose();
                    } else {
                        JOptionPane.showMessageDialog(this, rbMensajes.getString("MSG_UPD_ERROR"), rbMensajes.getString("MSG_MEN_PRI"), 0);
                    }
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
            }

        }
    }//GEN-LAST:event_jbtnAceptarActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        initMaster();
    }//GEN-LAST:event_formWindowOpened

    private void jcbAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbAreaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jcbAreaActionPerformed

    private void jcbDepartamentoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbDepartamentoItemStateChanged
        // TODO add your handling code here:
        if (!JUB._vacio(this.jcbDepartamento.getSelectedItem())) {
            cod_dep = ((Ubigeo) this.jcbDepartamento.getSelectedItem()).getCod_dep();
            llenarComboProvincias();
        }
    }//GEN-LAST:event_jcbDepartamentoItemStateChanged

    private void jcbProvinciaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbProvinciaItemStateChanged
        // TODO add your handling code here:
        if (!JUB._vacio(this.jcbProvincia.getSelectedItem())) {
            cod_prov = ((Ubigeo) this.jcbProvincia.getSelectedItem()).getCod_prov();
            cod_dep = ((Ubigeo) this.jcbDepartamento.getSelectedItem()).getCod_dep();
            llenarComboDistritos();
        }
    }//GEN-LAST:event_jcbProvinciaItemStateChanged

    private void jcbTipoCeseItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbTipoCeseItemStateChanged
        // TODO add your handling code here:
        if (this.jcbTipoCese.getSelectedIndex() == 0) {
            this.jdtFechaCese.setDate(null);
            this.jtxtMotivoCese.setText("");
            this.jdtFechaCese.setEnabled(false);
            this.jtxtMotivoCese.setEditable(false);
        } else {
            this.jdtFechaCese.setEnabled(true);
            this.jtxtMotivoCese.setEditable(true);
        }
    }//GEN-LAST:event_jcbTipoCeseItemStateChanged

    private void jcbDistritoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbDistritoItemStateChanged
        // TODO add your handling code here:
        if (!JUB._vacio(this.jcbDistrito.getSelectedItem())) {
            cod_dist = ((Ubigeo) this.jcbDistrito.getSelectedItem()).getCod_dist();
        }
    }//GEN-LAST:event_jcbDistritoItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormDialogMantPersonal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormDialogMantPersonal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormDialogMantPersonal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormDialogMantPersonal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                FormDialogMantPersonal dialog = new FormDialogMantPersonal(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton jbtnAceptar;
    private javax.swing.JButton jbtnCancelar;
    private javax.swing.JComboBox jcbArea;
    private javax.swing.JComboBox jcbCargo;
    private javax.swing.JComboBox jcbDepartamento;
    private javax.swing.JComboBox jcbDistrito;
    private javax.swing.JComboBox jcbEstadoCivil;
    private javax.swing.JComboBox jcbHorario;
    private javax.swing.JComboBox jcbProvincia;
    private javax.swing.JComboBox jcbSexo;
    private javax.swing.JComboBox jcbTipoCese;
    private javax.swing.JComboBox jcbTipoDocumento;
    private javax.swing.JComboBox jcbVia;
    private javax.swing.JComboBox jcbZona;
    private javax.swing.JCheckBox jchkEstado;
    private com.toedter.calendar.JDateChooser jdtFechaCese;
    private com.toedter.calendar.JDateChooser jdtFechaIngreso;
    private com.toedter.calendar.JDateChooser jdtFechaNacimiento;
    private javax.swing.JTextField jtxtApellidoMaterno;
    private javax.swing.JTextField jtxtApellidoPaterno;
    private javax.swing.JTextField jtxtCelular;
    private javax.swing.JTextField jtxtCodigo;
    private javax.swing.JTextField jtxtDireccion;
    private javax.swing.JTextField jtxtEmail;
    private javax.swing.JTextArea jtxtMotivoCese;
    private javax.swing.JTextField jtxtNumeroDocumento;
    private javax.swing.JTextArea jtxtObservacion;
    private javax.swing.JTextField jtxtPrimerNombre;
    private javax.swing.JTextField jtxtRemuneracion;
    private javax.swing.JTextField jtxtSegundoNombre;
    private javax.swing.JTextField jtxtTelefono;
    private javax.swing.JTextField jtxtZona;
    // End of variables declaration//GEN-END:variables

    public boolean isEsNuevo() {
        return esNuevo;
    }

    public void setEsNuevo(boolean esNuevo) {
        this.esNuevo = esNuevo;
    }

    public String getCodPersonal() {
        return codPersonal;
    }

    public void setCodPersonal(String codPersonal) {
        this.codPersonal = codPersonal;
    }

    @Override
    public boolean hayErroresInput() {
        if (JUB._vacio(this.jtxtNumeroDocumento.getText())) {
            JOptionPane.showMessageDialog(this, "CAMPO NUMERO DE DOCUMENTO NO PUEDE ESTAR VACIO", rbMensajes.getString("MSG_MEN_PRI"), 1);
            JUB.selectionJTextField(this.jtxtNumeroDocumento);
            return true;
        }

        if (this.jcbTipoDocumento.getSelectedIndex() == 0) {
            if (JUB.toUpperBlank(this.jtxtNumeroDocumento.getText()).length() > 8) {
                JOptionPane.showMessageDialog(this, "CAMPO NUMERO DE DOCUMENTO NO PUEDE TENER MAS DE 8 DIGITOS", rbMensajes.getString("MSG_MEN_PRI"), 1);
                JUB.selectionJTextField(this.jtxtNumeroDocumento);
                return true;
            }
        }
        if (this.jcbTipoDocumento.getSelectedIndex() == 2) {
            if (JUB.toUpperBlank(this.jtxtNumeroDocumento.getText()).length() > 11) {
                JOptionPane.showMessageDialog(this, "CAMPO NUMERO DE DOCUMENTO NO PUEDE TENER MAS DE 11 DIGITOS", rbMensajes.getString("MSG_MEN_PRI"), 1);
                JUB.selectionJTextField(this.jtxtNumeroDocumento);
                return true;
            }
        }

        if (JUB._vacio(this.jtxtApellidoPaterno.getText())) {
            JOptionPane.showMessageDialog(this, "CAMPO APELLIDO PATERNO NO PUEDE ESTAR VACIO", rbMensajes.getString("MSG_MEN_PRI"), 1);
            JUB.selectionJTextField(this.jtxtApellidoPaterno);
            return true;
        }

        if (JUB.toUpperBlank(this.jtxtApellidoPaterno.getText()).length() > 50) {
            JOptionPane.showMessageDialog(this, "CAMPO APELLIDO PATERNO NO PUEDE TENER MAS DE 50 CARACTERES", rbMensajes.getString("MSG_MEN_PRI"), 1);
            JUB.selectionJTextField(this.jtxtApellidoPaterno);
            return true;
        }

        if (JUB._vacio(this.jtxtApellidoMaterno.getText())) {
            JOptionPane.showMessageDialog(this, "CAMPO APELLIDO MATERNO NO PUEDE ESTAR VACIO", rbMensajes.getString("MSG_MEN_PRI"), 1);
            JUB.selectionJTextField(this.jtxtApellidoMaterno);
            return true;
        }

        if (JUB.toUpperBlank(this.jtxtApellidoMaterno.getText()).length() > 50) {
            JOptionPane.showMessageDialog(this, "CAMPO APELLIDO MATERNO NO PUEDE TENER MAS DE 50 CARACTERES", rbMensajes.getString("MSG_MEN_PRI"), 1);
            JUB.selectionJTextField(this.jtxtApellidoMaterno);
            return true;
        }
        if (JUB._vacio(this.jtxtPrimerNombre.getText())) {
            JOptionPane.showMessageDialog(this, "CAMPO PRIMER NOMBRE NO PUEDE ESTAR VACIO", rbMensajes.getString("MSG_MEN_PRI"), 1);
            JUB.selectionJTextField(this.jtxtPrimerNombre);
            return true;
        }

        if (JUB.toUpperBlank(this.jtxtPrimerNombre.getText()).length() > 50) {
            JOptionPane.showMessageDialog(this, "CAMPO PRIMER NOMBRE NO PUEDE TENER MAS DE 50 CARACTERES", rbMensajes.getString("MSG_MEN_PRI"), 1);
            JUB.selectionJTextField(this.jtxtPrimerNombre);
            return true;
        }

        if (JUB.toUpperBlank(this.jtxtSegundoNombre.getText()).length() > 50) {
            JOptionPane.showMessageDialog(this, "CAMPO SEGUNDO NOMBRE NO PUEDE TENER MAS DE 50 CARACTERES", rbMensajes.getString("MSG_MEN_PRI"), 1);
            JUB.selectionJTextField(this.jtxtPrimerNombre);
            return true;
        }

        if (JUB._vacio(this.jdtFechaNacimiento.getDate())) {
            JOptionPane.showMessageDialog(this, "CAMPO FECHA DE NACIMIENTO NO PUEDE ESTAR VACACIO", rbMensajes.getString("MSG_MEN_PRI"), 1);
            this.jdtFechaNacimiento.requestFocus();
            return true;
        }

        if (this.jcbTipoCese.getSelectedIndex() > 0) {
            if (JUB._vacio(this.jtxtMotivoCese.getText())) {
                JOptionPane.showMessageDialog(this, "CAMPO MOTIVO DE CESE NO PUEDE ESTAR VACIO SI SE ELIGIO UN TIPO DE CESE", rbMensajes.getString("MSG_MEN_PRI"), 1);
                this.jtxtMotivoCese.requestFocus();
                return true;
            }

            if (JUB._vacio(this.jdtFechaCese.getDate())) {
                JOptionPane.showMessageDialog(this, "CAMPO FECHA DE CESE NO PUEDE ESTAR VACIO SI SE ELIGIO UN TIPO DE CESE", rbMensajes.getString("MSG_MEN_PRI"), 1);
                this.jdtFechaCese.requestFocus();
                return true;
            }
        }

        return false;
    }

    @Override
    public void getEntity() {
        try {
            entityPersonal = new Personal();
            entityPersonal.setCod_per(JUB.toUpperBlank(this.jtxtCodigo.getText()));
            entityPersonal.setCod_tip_doc(((TipoDocumento) this.jcbTipoDocumento.getSelectedItem()).getCod_tip_doc());
            entityPersonal.setNum_ide(JUB.toUpperBlank(this.jtxtNumeroDocumento.getText()));
            entityPersonal.setApe_pat(JUB.toUpperBlank(this.jtxtApellidoPaterno.getText()));
            entityPersonal.setApe_mat(JUB.toUpperBlank(this.jtxtApellidoMaterno.getText()));
            entityPersonal.setPri_nom(JUB.toUpperBlank(this.jtxtPrimerNombre.getText()));
            entityPersonal.setSeg_nom(JUB.toUpperBlank(this.jtxtSegundoNombre.getText()));
            entityPersonal.setFec_nac(JUB.toDateTime(this.jdtFechaNacimiento.getDate()));
            entityPersonal.setSex_per(JUB.toUpperBlank(jcbSexo.getSelectedItem().toString().substring(0, 1)));
            entityPersonal.setEst_civ(JUB.toUpperBlank(jcbEstadoCivil.getSelectedItem().toString().substring(0, 1)));
            entityPersonal.setMail_per(JUB.toUpperBlank(this.jtxtEmail.getText()));
            entityPersonal.setTel_per(JUB.toUpperBlank(this.jtxtTelefono.getText()));
            entityPersonal.setCel_per(JUB.toUpperBlank(this.jtxtCelular.getText()));

            Ubigeo oUbigeo = logic.getUbigeo(cod_dep, cod_prov, cod_dist);
            entityPersonal.setId_ubigeo(oUbigeo.getId());
            entityPersonal.setCod_via(((Via) this.jcbVia.getSelectedItem()).getCod_via());
            entityPersonal.setCod_zon(((Zona) this.jcbZona.getSelectedItem()).getCod_zon());
            entityPersonal.setDir_per(JUB.toUpperBlank(this.jtxtDireccion.getText()));
            entityPersonal.setZon_per(JUB.toUpperBlank(this.jtxtZona.getText()));
            entityPersonal.setObserv(JUB.toUpperBlank(this.jtxtObservacion.getText()));

            entityPersonal.setCod_are(((Area) this.jcbArea.getSelectedItem()).getCod_are());
            entityPersonal.setCod_car(((Cargo) this.jcbCargo.getSelectedItem()).getCod_car());
            entityPersonal.setCod_hor(((Horario) this.jcbHorario.getSelectedItem()).getCod_hor());
            entityPersonal.setCod_ces(JUB.toUpperBlank(jcbTipoCese.getSelectedItem().toString().substring(0, 2)));
            entityPersonal.setMot_ces(JUB.toUpperBlank(jtxtMotivoCese.getText()));
            entityPersonal.setFec_ing(JUB.toDateTime(this.jdtFechaIngreso.getDate()));
            entityPersonal.setFec_ces(JUB.toDateTime(this.jdtFechaCese.getDate()));
            entityPersonal.setRemuner(JUB.toDouble(this.jtxtRemuneracion.getText()));

            if (!JUB._vacio(entityPersonal.getFec_ces())) {
                entityPersonal.setEstado("I");
            } else {
                entityPersonal.setEstado(this.jchkEstado.isSelected() ? "A" : "I");
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
        }
    }

    @Override
    public void initMaster() {
        llenarComboAreas();
        llenarComboHorarios();
        llenarComboCargos();
        llenarComboVias();
        llenarComboZonas();
        llenarComboTipoDocumentos();
        llenarComboDepartamentos();
        Date fecNac = DateTime.now().plusYears(-18).toDate();
        Date hoy = DateTime.now().toDate();
        this.jtxtCodigo.setDocument(new JTextFieldToUpperCase());
        this.jtxtApellidoPaterno.setDocument(new JTextFieldToUpperCase());
        this.jtxtApellidoMaterno.setDocument(new JTextFieldToUpperCase());
        this.jtxtPrimerNombre.setDocument(new JTextFieldToUpperCase());
        this.jtxtSegundoNombre.setDocument(new JTextFieldToUpperCase());
        this.jtxtEmail.setDocument(new JTextFieldToUpperCase());
        this.jtxtDireccion.setDocument(new JTextFieldToUpperCase());
        this.jtxtObservacion.setDocument(new JTextFieldToUpperCase());
        this.jtxtZona.setDocument(new JTextFieldToUpperCase());
        this.jtxtMotivoCese.setDocument(new JTextFieldToUpperCase());
        this.jtxtRemuneracion.setText("0.00");

        this.jtxtNumeroDocumento.setDocument(new JTextFieldToUpperCase(12, true));
        this.jtxtTelefono.setDocument(new JTextFieldToUpperCase(12, true));
        this.jtxtCelular.setDocument(new JTextFieldToUpperCase(12, true));
        this.jdtFechaNacimiento.setDate(fecNac);
        this.jdtFechaIngreso.setDate(hoy);
        llenarData();

    }

    @Override
    public void setEntity(Object entity) {
        try {
            Personal oPersonal = (Personal) entity;
            this.jtxtCodigo.setText(oPersonal.getCod_per());
            this.jcbTipoDocumento.setSelectedIndex(findComboGeneral(oPersonal.getCod_tip_doc(), jcbTipoDocumento));
            this.jtxtNumeroDocumento.setText(oPersonal.getNum_ide());
            this.jtxtApellidoPaterno.setText(oPersonal.getApe_pat());
            this.jtxtApellidoMaterno.setText(oPersonal.getApe_mat());
            this.jtxtPrimerNombre.setText(oPersonal.getPri_nom());
            this.jtxtSegundoNombre.setText(oPersonal.getSeg_nom());
            this.jdtFechaNacimiento.setDate(JUB.toDateTimeSQL(oPersonal.getFec_nac()));
            this.jcbSexo.setSelectedIndex(findComboGeneral(oPersonal.getSex_per(), jcbSexo));
            this.jcbEstadoCivil.setSelectedIndex(findComboGeneral(oPersonal.getEst_civ(), jcbEstadoCivil));
            this.jtxtEmail.setText(oPersonal.getMail_per());
            this.jtxtTelefono.setText(oPersonal.getTel_per());
            this.jtxtCelular.setText(oPersonal.getCel_per());

            Ubigeo oUbigeo = logic.getByPk(oPersonal.getId_ubigeo());
            this.jcbDepartamento.setSelectedIndex(findComboGeneral(oUbigeo.getCod_dep() + "0000", jcbDepartamento));
            this.jcbProvincia.setSelectedIndex(findComboGeneral(oUbigeo.getCod_dep() + oUbigeo.getCod_prov() + "00", jcbProvincia));
            this.jcbDistrito.setSelectedIndex(findComboGeneral(oUbigeo.getCod_dep() + oUbigeo.getCod_prov() + oUbigeo.getCod_dist(), jcbDistrito));
            this.jcbVia.setSelectedIndex(findComboGeneral(oPersonal.getCod_via(), jcbVia));
            this.jcbZona.setSelectedIndex(findComboGeneral(oPersonal.getCod_zon(), jcbZona));
            this.jtxtDireccion.setText(oPersonal.getDir_per());
            this.jtxtZona.setText(oPersonal.getZon_per());
            this.jtxtObservacion.setText(oPersonal.getObserv());

            this.jcbArea.setSelectedIndex(findComboGeneral(oPersonal.getCod_are(), jcbArea));
            this.jcbCargo.setSelectedIndex(findComboGeneral(oPersonal.getCod_car(), jcbCargo));
            this.jcbHorario.setSelectedIndex(findComboGeneral(oPersonal.getCod_hor(), jcbHorario));
            this.jcbTipoCese.setSelectedIndex(findComboGeneral(oPersonal.getCod_ces(), jcbTipoCese));
            this.jtxtMotivoCese.setText(oPersonal.getMot_ces());

            this.jtxtRemuneracion.setText(JUB.toString(oPersonal.getRemuner()));
            this.jdtFechaIngreso.setDate(JUB.toDateTimeSQL(oPersonal.getFec_ing()));
            this.jdtFechaCese.setDate(JUB.toDateTimeSQL(oPersonal.getFec_ces()));

            this.jchkEstado.setSelected(oPersonal.getEstado().equals("A"));
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), rbMensajes.getString("MSG_MEN_PRI"), 0);
        }
    }

    private int findComboGeneral(String codigo, JComboBox combo) {
        int idx = 0;

        for (int i = 0; i < combo.getItemCount(); i++) {
            String[] data = combo.getItemAt(i).toString().split("-");
            if (JUB._equiv(data[0], codigo)) {
                return i;
            }
        }
        return idx;

    }

}
